package org.jetlinks.community.device.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType;
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
import org.hswebframework.ezorm.rdb.mapping.annotation.JsonCodec;
import org.hswebframework.web.api.crud.entity.GenericTreeSortSupportEntity;
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
import org.hswebframework.web.validator.CreateGroup;

import javax.persistence.Column;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.sql.JDBCType;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@Table(name = "s_region")
@Comment("区域管理")
@EnableEntityEvent
public class Region extends GenericTreeSortSupportEntity<String> {

    @Comment("区域ID")
    @Column(length = 32, name = "id")
    @Schema(description = "唯一ID")
    private String id;

    @Comment("区域名称")
    @Column(length = 128, name = "r_name")
    @Schema(description = "名称")
    private String name;

    @Schema(description = "子区域")
    private List<Region> children;

    @Pattern(
        regexp = "^[0-9a-zA-Z_\\-]+$",
        message = "ID只能由数字,字母,下划线和中划线组成",
        groups = {CreateGroup.class}
    )
    public String getId() {
        return (String)super.getId();
    }

}
